package util;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class RegraValida {

    public void validaTexto(String nome) throws EmptyFiledException {
        if (nome.isEmpty()) {
            throw new EmptyFiledException();
        }
    }

    public void validaInteiro(String numero) throws EmptyFiledException, NumberFormatException {
        if (numero.isEmpty()) {
            throw new EmptyFiledException();
        }

        Integer.parseInt(numero);
    }

    public void validaPontoFlutuante(String numero) throws EmptyFiledException, NumberFormatException {
        if (numero.isEmpty()) {
            throw new EmptyFiledException();
        }

        Double.parseDouble(numero.replace(",", "."));
    }

    public void validaData(String data, String formato) throws EmptyFiledException, ParseException {
        if (data.isEmpty()) {
            throw new EmptyFiledException();
        }

        if (formato != null) {
            new SimpleDateFormat(formato).parse(data);
        }
    }
}
